package com.ms.dsq_english.http;

import com.ms.dsq_english.utils.LogUtils;

import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

public class HttpManager
{
    public static final String TAG = "HttpConnect";

    //正式
    public static final String URL = "https://msapi.rfc-friso.com/";
    //uat
//    public static final String URL = "https://msapi-uat.rfc-friso.com/";
    //测试
//    public static final String URL = "https://ms-api-uat.51dh.vip/";

    public static HttpInterface getRetrofitInterface()
    {
        return new Retrofit
                .Builder()
                .baseUrl(URL)
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .addConverterFactory(GsonConverterFactory.create())
                .callFactory(new OkHttpClient.Builder()
                        .addInterceptor(new HttpLoggingInterceptor(message -> LogUtils.showLog(TAG, message)).setLevel(HttpLoggingInterceptor.Level.BODY))
                        .addInterceptor(new HttpInterceptor())
                        .connectTimeout(10, TimeUnit.SECONDS)
                        .readTimeout(10, TimeUnit.SECONDS)
                        .writeTimeout(10, TimeUnit.SECONDS)
                        .build())
                .build()
                .create(HttpInterface.class);
    }
}
